package com.chenken;

import java.util.Comparator;

import com.chenken.heap.BinaryHeap;

/**
 * 优先级队列
 * 使用二叉堆作为底层
 */
public class PriorityQueue<E> {

	private BinaryHeap<E> binaryHeap;
	
	public PriorityQueue(Comparator<E> comparator){
		binaryHeap = new BinaryHeap<E>(comparator);
	}
	
	public PriorityQueue(){
		this(null);
	}
	
	public int size() {
		return binaryHeap.size();
	}
	
	public boolean isEmpty() {
		return binaryHeap.isEmpty();
	}
	
	/**
	 * 入队
	 * @param element
	 */
	public void enQueue(E element) {
		binaryHeap.add(element);
	}
	
	/**
	 * 出队
	 * @return
	 */
	public E deQueue() {
		return binaryHeap.remove();
	}
	
	/**
	 * 得到队头元素
	 * @return
	 */
	public E front() {
		return binaryHeap.get();
	}
	
}
